package dj.common.exception;

import lombok.Getter;
import lombok.Setter;

/**
 * <br>
 * <p>Exception基类</p>
 *
 * <br>
 * @author ZJG
 * @version 1.0
 * @date 2021/7/7 下午2:19
 */
@Setter
@Getter
public class BaseException extends Exception {

    /**
     * 业务领域code
     */
    protected String domainCode = null;

    /**
     * 异常msg
     */
    protected String message = null;

    /**
     * 异常code
     */
    protected int code = 500;

    public BaseException(String message) {
        super(message);
        this.message = message;
    }

    public BaseException(Throwable cause) {
        super(cause);
    }

    public BaseException(int code, String message) {
        super("error_code='" + code + "', error_msg='" + message + "'");
        this.code = code;
        this.message = message;
    }


    public BaseException(String domainCode, int code, String message) {
        super(domainCode + ", error_code='" + code + "', error_msg='" + message + "'");
        this.domainCode = domainCode;
        this.code = code;
        this.message = message;
    }

    public BaseException(String domainCode, Throwable cause) {
        super(domainCode + " of an exception occurred. err_msg: " + cause.getMessage(), cause);
        this.domainCode = domainCode;
        this.message = domainCode + " of an exception occurred. err_msg: " + cause.getMessage();
    }

    public BaseException(String domainCode,  int code, String message, Throwable cause) {
        super(cause);
        this.domainCode = domainCode;
        this.message = message;
        this.code = code;
    }
}
